﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufInputControl.h"
#include <QtCore/QPointer>
#include <QWidget>
class QWidget;
namespace gnuf {
    
    class Info;

    class GNUF_BASE_EXPORT IWidgetAgentControlHandler
        : public IInputControlHandler
    {
    public:
    };
    
    class GNUF_BASE_EXPORT WidgetAgentControlAdpatation
        : public InputControlAdaptation
    {
    protected:
        WidgetAgentControlAdpatation();
        virtual ~WidgetAgentControlAdpatation();

        //
        // Inherits from InputControlAdaptation...
        virtual void onVisibilityChanged(bool) override {}
        virtual void onAbilityChanged(bool) override {}
        virtual void onSelectionChanged(bool) override {}
    };
    
    class GNUF_BASE_EXPORT WidgetAgentControl
        : public InputControl
    {
        CANNOT_COPY_OR_ASSIGN(WidgetAgentControl)
    public:
        static const EItemType Type;
        WidgetAgentControl(IWidgetAgentControlHandler *, QWidget *,
            gcmp::OwnerPtr< Info > & info, bool transferOwnership);
        virtual ~WidgetAgentControl();
        
        inline QWidget * qtWidget() const { return m_qtWidget.data(); }
        inline QWidget * takeAwayQtWidget() const;

        inline const Info * info() const { return m_info.get(); }

        inline bool transferOwnership() const { return m_transferOwnership; }
        
    private:
        mutable QPointer<QWidget> m_qtWidget;
        gcmp::OwnerPtr< Info > m_info;
        const bool m_transferOwnership;
    };
    
}
